/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.NiftyEventSubscriber;
import de.lessvoid.nifty.controls.ButtonClickedEvent;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

/**
 * @date 2024年7月11日17点34分
 * @author JohnKkk
 */
public class NiftyGuiButton extends SimpleApplication implements ScreenController{

    private Nifty m_Nifty;

    @Override
    public void simpleInitApp() {
        // 初始化Nifty
        NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay(
                assetManager,
                inputManager,
                audioRenderer,
                guiViewPort);
        m_Nifty = niftyDisplay.getNifty();
        // 将NiftyGUI显示对象添加到JME3中
        guiViewPort.addProcessor(niftyDisplay);
        
        m_Nifty.fromXml("Interface/NiftyGuiButton.xml", "screen0");
        
        // 禁用flyCam并显示鼠标
        flyCam.setEnabled(false);
        inputManager.setCursorVisible(true);
    }
    
    public static void main(String[] args) {
        NiftyGuiButton niftyGuiButton = new NiftyGuiButton();
        niftyGuiButton.start();
    }
    
    @NiftyEventSubscriber(id="testButton")
    public final void onButtonClickedEvent(final String id, final ButtonClickedEvent event){
        System.out.println("id:" + id + ",EventBus通知!");
    }
    
    /**
     * 按钮点击回调事件.<br/>
     * @param text 传递的参数
     */
    public void onClickEvent(String text){
        System.out.println(text);
    }
    
    /**
     * 鼠标释放按钮回调事件.<br/>
     */
    public void onReleaseEvent(){
        System.out.println("鼠标释放按钮");
    }
    
    /**
     * 多次点击事件回调.<br/>
     */
    public void onMultiClickEvent(){
        System.out.println("鼠标多次点击");
    }

    @Override
    public void bind(Nifty nifty, Screen screen) {
    }

    @Override
    public void onStartScreen() {
    }

    @Override
    public void onEndScreen() {
    }
}
